<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>订单</title>
		<link rel="stylesheet" type="text/css" href="/static/admin/layui/css/layui.css" />
		<link rel="stylesheet" type="text/css" href="/static/admin/css/admin.css" />
	</head>
	<body>
		<div class="wrap-container">
			<form class="layui-form" style="width: 90%;padding-top: 20px;">
				<input type="text" name="id" th:value="${pd.pdId}" hidden>
				<input type="text" name="pay" th:value="${order.pay}" hidden>
					<div class="layui-form-item">
						<label class="layui-form-label">产品名：</label>
						<div class="layui-input-block">
							<input type="text" th:value="${pd.pdName}" readonly="readonly" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
								<label class="layui-form-label">产品单价：</label>
								<div class="layui-input-block">
									<input type="text" th:value="${pd.pdPrice}" readonly="readonly" class="layui-input">
								</div>
							</div>
					<div class="layui-form-item">
								<label class="layui-form-label">购买数量：</label>
								<div class="layui-input-block">
									<input type="text" name="num" th:value="${order.num}" readonly="readonly" class="layui-input">
								</div>
							</div>
					<div class="layui-form-item">
								<label class="layui-form-label">支付方式：</label>
								<div class="layui-input-block">
									<input type="text" th:if="${order.pay==1}" value="支付宝" readonly="readonly" class="layui-input">
									<input type="text" th:if="${order.pay==2}" value="QQ钱包" readonly="readonly" class="layui-input">
								</div>
							</div>
					<div class="layui-form-item">
								<label class="layui-form-label">联系方式：</label>
								<div class="layui-input-block">
									<input type="text" name="contact" th:value="${order.contact}" readonly="readonly" class="layui-input">
								</div>
							</div>
					<div class="layui-form-item">
								<label class="layui-form-label">提取密码：</label>
								<div class="layui-input-block">
									<input type="text" name="password" th:value="${order.password}" readonly="readonly" class="layui-input">
								</div>
							</div>
					<div class="layui-form-item" style="margin-bottom: 25px;">
						<label class="layui-form-label">应付金额:</label>
						<div class="layui-input-block">
							<h1 style="color:crimson;font-weight:bold;display:inline ;font-size: 31px;" th:text="|￥${pd.pdPrice*order.num}|">0.01</h1>
						</div>
					</div>



					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit lay-filter="formDemo">立即支付</button>
						</div>
					</div>
				</form>
		</div>

		<script src="/static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script>
			//Demo
			layui.use(['form','jquery'], function() {
				var form = layui.form();
				var $ = layui.jquery;
				form.render();
				//监听提交
				form.on('submit(formDemo)', function(data) {
					//layer.msg(JSON.stringify(data.field));
                    $.ajax({
                        url:"/pay/",
                        type:"post",
                        data:data.field,
                        dateType:"json",
                        success:function (res) {
                            var obj;
                            //判断是否是json格式
                            if((typeof res=='object')&&res.constructor==Object){
                                obj=res;
                            }else{
                                obj  = eval("("+res+")");
                            }
                            if(obj.code != 1){
                                layer.msg(obj.msg);
                            }else{
                                window.location.href=obj.url;
								var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
								parent.layer.title('支付订单', index)  //再改变当前层的标题
                            }
                        }
                    });
					return false;
				});
			});
		</script>
	</body>

</html>